package com.talent.jiwen;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;

import com.jaeger.library.StatusBarUtil;
import com.talent.jiwen.util.LogUtil;
import com.talent.jiwen.util.MobileInfoUtil;
import com.talent.jiwen.util.SPConstant;
import com.talent.jiwen.util.SPUtil;
import com.talent.jiwen.util.Validators;

/**
 * Created by qyqx on 2018/7/4.
 * 欢迎页
 */

public class SplashActivity extends AppCompatActivity {

    private Context context;

    private RelativeLayout rl_splash;

    AlphaAnimation alpha;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash);
//        StatusBarUtil.setColor(this, getResources().getColor(R.color.black_20),20);
        StatusBarUtil.setTranslucent(this,40);
        ActivityManager.getAppManager().addActivity(this);
        context = this;
        rl_splash= (RelativeLayout) findViewById(R.id.rl_splash);

        startAnimation();
    }




    private void startAnimation() {
        alpha = new AlphaAnimation(0, 1);
        alpha.setDuration(2000);
        alpha.setFillAfter(true);
        rl_splash.setAnimation(alpha);
        alpha.startNow();
        alpha.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }
            @Override
            public void onAnimationEnd(Animation animation) {
                String token= SPUtil.stringOut(SPConstant.TOKEN);
//                String nimToken= SPUtil.stringOut(SPConstant.NIM_TOKEN);
                if(!Validators.isEmpty(token)){
//                    startActivity(new Intent(SplashActivity.this,MainActivity.class));
                    startActivity(new Intent(SplashActivity.this,IndexActivity.class));
                }else{
                    startActivity(new Intent(SplashActivity.this,GuideActivity.class));
                }
                finish();

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        alpha.cancel();
        rl_splash.clearAnimation();
        ActivityManager.getAppManager().finishActivity(this);
    }

}
